package org.jivesoftware.smackx.workgroup.agent;

import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smackx.workgroup.packet.Transcript;
import org.jivesoftware.smackx.workgroup.packet.Transcripts;

public class TranscriptManager
{
  private Connection connection;

  public TranscriptManager(Connection paramConnection)
  {
    this.connection = paramConnection;
  }

  public Transcript getTranscript(String paramString1, String paramString2)
    throws XMPPException
  {
    Transcript localTranscript1 = new Transcript(paramString2);
    localTranscript1.setTo(paramString1);
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localTranscript1.getPacketID()));
    this.connection.sendPacket(localTranscript1);
    Transcript localTranscript2 = (Transcript)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localTranscript2 == null)
      throw new XMPPException("No response from server on status set.");
    if (localTranscript2.getError() != null)
      throw new XMPPException(localTranscript2.getError());
    return localTranscript2;
  }

  public Transcripts getTranscripts(String paramString1, String paramString2)
    throws XMPPException
  {
    Transcripts localTranscripts1 = new Transcripts(paramString2);
    localTranscripts1.setTo(paramString1);
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localTranscripts1.getPacketID()));
    this.connection.sendPacket(localTranscripts1);
    Transcripts localTranscripts2 = (Transcripts)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localTranscripts2 == null)
      throw new XMPPException("No response from server on status set.");
    if (localTranscripts2.getError() != null)
      throw new XMPPException(localTranscripts2.getError());
    return localTranscripts2;
  }
}